//创建store
const useStore = new defineStore('shopping', {
    state()
    {
        return {
            business:{
                id: 0,
                mobile: "",
                nickname: "",
                avatar: "",
                gender: "0",
                sourceid: 0,
                deal: "0",
                openid: null,
                province: "",
                city: "",
                district: "",
                createtime: 0,
                money: "0",
                email: "",
                auth: "0",
                poster: "",
                parentid: 0,
                avatar_text: "",
                poster_text: "",
                province_text: "",
                city_text: "",
                district_text: "",
                createtime_text: "",
                region_text: "",
                deletetime_text: "",
                gender_text: "保密",
                deal_text: "未成交",
                auth_text: "未认证"
            },
            address: null
        }
    },
    persist: {
        enabled: true,//开启数据保持化
        strategies: [
            {
                key:'shopping',//给一个要保存的名称
                storage: localStorage,//sessionStorage / localStorage 存储方式
            }
        ]
    },
})

export default {
    install(app)
    {
        //提取store数据是一个ref定义响应式
        const store = useStore()
        const {business,address} = storeToRefs(store)

        //挂载到全局中 
        app.config.globalProperties.$business = business
        app.config.globalProperties.$address = address
        app.config.globalProperties.$store = store
    }
}